#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Quick fix: Update WeatherDaily model to match existing database schema
"""

import sys
from pathlib import Path

# Add project root to Python path
project_root = Path(__file__).parent.absolute()
sys.path.insert(0, str(project_root))

def check_existing_schema():
    """Check what columns actually exist in weather_daily table"""
    try:
        from backend.config.database import engine
        from sqlalchemy import inspect
        
        print("🔍 检查现有 weather_daily 表结构...")
        
        inspector = inspect(engine)
        if 'weather_daily' in inspector.get_table_names():
            columns = inspector.get_columns('weather_daily')
            print("现有列:")
            for col in columns:
                print(f"  - {col['name']}: {col['type']}")
            
            # Generate a compatible model
            existing_cols = [col['name'] for col in columns]
            
            print("\n建议的模型修改:")
            print("移除或注释掉这些不存在的列:")
            model_cols = ['ws_max', 'pressure', 'uv_index', 'data_source', 'updated_at']
            for col in model_cols:
                if col not in existing_cols:
                    print(f"  - {col}")
                    
        else:
            print("❌ weather_daily 表不存在")
            
    except Exception as e:
        print(f"❌ 检查失败: {e}")

if __name__ == "__main__":
    check_existing_schema()